package jmetal.metaheuristics.grdea;

import java.util.HashMap;

import jmetal.core.Algorithm;
import jmetal.core.Operator;
import jmetal.core.Problem;
import jmetal.core.SolutionSet;
import jmetal.operators.crossover.CrossoverFactory;
import jmetal.operators.mutation.MutationFactory;
import jmetal.operators.selection.SelectionFactory;
import jmetal.problems.DTLZ.DTLZ1;
import jmetal.problems.DTLZ.DTLZ2;
import jmetal.problems.DTLZ.DTLZ3;
import jmetal.problems.DTLZ.DTLZ4;
import jmetal.problems.DTLZ.DTLZ6;
import jmetal.problems.DTLZ.DTLZ7;
import jmetal.problems.ZDT.ZDT1;
import jmetal.problems.cec2009Competition.UF1;
import jmetal.problems.cec2009Competition.UF2;
import jmetal.problems.ddtlz.F1;
import jmetal.problems.ddtlz.F2;
import jmetal.problems.ddtlz.F3;
import jmetal.problems.ddtlz.F4;
import jmetal.problems.glt.GLT3;
import jmetal.util.JMException;

public class GrdEA_main {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void main(String[] args) throws JMException, ClassNotFoundException {
		Problem problem = new F1(7,0);//时钟应默认为0
		Algorithm algorithm = new GrdEA(problem);
		HashMap parameters;
		
	    algorithm.setInputParameter("populationSize",300);
	    algorithm.setInputParameter("maxEvaluations",300*1001);
	    algorithm.setInputParameter("numberOfGrids", 30);
	    
	    // Mutation and Crossover for Real codification 
	    parameters = new HashMap() ;
	    parameters.put("probability", 1.0) ;
	    parameters.put("distributionIndex", 30.0) ;
	    Operator crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters);                   

	    parameters = new HashMap() ;
	    parameters.put("probability", 1.0/problem.getNumberOfVariables()) ;
	    parameters.put("distributionIndex", 20.0) ;
	    Operator mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters);                    

	    // Selection Operator 
	    parameters = null ;
	    Operator selection = SelectionFactory.getSelectionOperator("BinaryTournament", parameters) ;                           

	    // Add the operators to the algorithm
	    algorithm.addOperator("crossover",crossover);
	    algorithm.addOperator("mutation",mutation);
	    algorithm.addOperator("selection",selection);
	    
	    long time = System.currentTimeMillis();
	    SolutionSet population = algorithm.execute();
	    System.out.println("use"+(System.currentTimeMillis()-time)+"ms");
	    population.printObjectivesToFile("output_data/FUN_"+problem.getNumberOfObjectives());
	}
}
